﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DotSpatialExcelAddIn
{
    public partial class frmSelectActiveSheet : Form
    {
        public int SelectedSheet
        {
            get { return cmbSheet.SelectedIndex ;}
            set {}
        }
        
        public frmSelectActiveSheet()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
       
            this.Close(); 
        }

        private void frmSelectActiveSheet_Load(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application oXL;
            Microsoft.Office.Interop.Excel.Workbook oWB;
            Microsoft.Office.Interop.Excel.Worksheet oSheet;
            oXL = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
            oXL.Visible = true;
            oWB = (Microsoft.Office.Interop.Excel.Workbook)oXL.ActiveWorkbook;
            int lastSheet = oWB.Worksheets.Count;

            cmbSheet.Items.Add("New sheet");
            cmbSheet.SelectedIndex = 0;
            for (int i = 1; i <= lastSheet; i++)
            {
                cmbSheet.Items.Add( oWB.Worksheets[i].name);
            }
        }
    }
}
